package org.academic.texteditor.gui.plugin.text;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.KeyStroke;

import org.academic.texteditor.gui.component.PageContainer;
import org.academic.texteditor.gui.component.PersonalizedTextPane;
import org.academic.texteditor.gui.component.menu.MenuFactory;
import org.academic.texteditor.gui.feature.Page;
import org.academic.texteditor.gui.plugin.BasePlugin;

public class MarkTextPlugin extends BasePlugin {

	private static final long serialVersionUID = -5755629904293536498L;
	
	private PageContainer pageContainer;

	public MarkTextPlugin() {
		super("markText");
	}

	@Override
	public void initialize(PageContainer pageContainer) {
		this.pageContainer = pageContainer;
	}

	@Override
	public void activate() {
		JMenu menuEdit = MenuFactory.getEdit();
		MenuFactory.createMenuItem(menuEdit, 3, "markText", "menu.edit.markText", this).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
	}

	@Override
	public void execute() {
		Page page = pageContainer.getActualPage();
		if (page == null) {
			return;
		}
		
		PersonalizedTextPane textPane = page.getText().getTextPane();
		if (!textPane.isStyleCharacter("Mark")) {
			textPane.applyStyleCharacter("Mark");
		} else {
			textPane.removeStyleParagraph();
		}
	}

	@Override
	public void deactivate() {
		JMenu menuEdit = MenuFactory.getEdit();
		MenuFactory.removeMenuItem(menuEdit, "markText");
	}

	@Override
	public void destroy() {

	}

}
